import {Button, Form, Input, message as Message, Space} from "antd";
import SwitchDark from "../../component/SwitchDark";
import {LockOutlined, UserOutlined} from "@ant-design/icons";
import {connect} from "react-redux";
import {setToken} from "../../redux/modules/global/action";
import {useNavigate} from "react-router-dom"
import './style/loginIndex.scss'
import {loginApi} from "@/api/modules/login";
import "../../utils/smUtil/smUtil";



function LoginIndex (props){
    let {setToken} = props;
    let navigate = useNavigate();

    let onFinish = async param => {
        let name = param.username;
        param.origin='react';
        if(name) {
            /*let {status, message} = await loginApi(param);
            if(status == 200){
                Message.success(message);
                setToken(name);
                navigate('/home/index');
            } else {
                Message.error(message)
            }*/
            setToken(name);
            navigate('/home/index');
        }
    }

    return(
        <div className='loginBox login-container'>
            <Form
                name="wrap"
                labelCol={{ span: 5 }}
                labelAlign="left"
                labelWrap
                wrapperCol={{ flex: 1 }}
                size="large"
                autoComplete="off"
                style={{ maxWidth: 400 }}
                onFinish={onFinish}
            >
                <h3>登录</h3>
                <Form.Item name="username" rules={[{ required: true , message: '请输入用户名称'}]}>
                    <Input allowClear prefix={<UserOutlined />} placeholder={'请输入用户名称'}/>
                </Form.Item>

                <Form.Item name="password" rules={[{ required: true,  message: '请输入密码' }]}>
                    <Input type={"password"} prefix={<LockOutlined />} placeholder={'请输入密码'}/>
                </Form.Item>

                <Form.Item>
                    <Space>
                        <Button type="primary" htmlType="submit"> 提交 </Button>
                        <Button htmlType="reset">Reset</Button>
                    </Space>
                </Form.Item>
            </Form>
            <SwitchDark class='switch'/>
        </div>
    )
}
const mapDispatchToProps = {setToken}

export default connect(null, mapDispatchToProps)(LoginIndex);
